package com.twu.biblioteca.ui;

import java.util.Scanner;

import com.twu.biblioteca.Persistence.UserRepository;
import com.twu.biblioteca.library.UserLoginController;

/**
 * Created by S ARUNA on 23-04-2014.
 */
public class BibilioTechaUI {
private int loggedInMenu=0;
    public void run() {

        System.out.println("-----------------------------------------------");
        System.out.println(getWelcomeMessage());
        System.out.println("-----------------------------------------------");
        loginMenu();
        }
    public void loginMenu()
    {
        String librarynumber,password;
        char continuechoice='c';
        do {
            System.out.println("Enter your library number");
            librarynumber = acceptString();
            System.out.println("Enter your password");
            password = acceptString();

            if (UserLoginController.login(librarynumber, password)) {
                loggedInMenu = 1;
                LoggedInUserMenu l = new LoggedInUserMenu(UserRepository.getUserByLibraryNumber(librarynumber));
                l.displayMenu();

            } else {
                System.out.println("Please press c to try again to continue and q to exit!");
                continuechoice=acceptCharacter();
            }
        }while(continuechoice != 'q');
    }
    private char acceptCharacter()
    {
        Scanner inputScanner=new Scanner(System.in);
        char choice;
        choice = inputScanner.next().charAt(0);
        return choice;
    }
    private String acceptString()
    {
        Scanner inputScanner=new Scanner(System.in);
        String str=inputScanner.next();
        return str;
    }

    //For user story 1
    public String getWelcomeMessage() {
        return "Welcome to Bibiliotecha";
    }

    }
